package com.shuaigef.springbootinit.bean;

import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class HttpBean {
    public static OkHttpClient okHttpClient = new OkHttpClient.Builder()
            .connectTimeout(6, TimeUnit.MINUTES)
            .readTimeout(6, TimeUnit.MINUTES)
            .writeTimeout(6, TimeUnit.MINUTES)
            .build();
    public static MediaType jsonMediaType = MediaType.parse("application/json; charset=utf-8");
    public static MediaType formMediaType = MediaType.parse("application/x-www-form-urlencoded");
    @Bean
    public OkHttpClient client() {
        if(okHttpClient == null) HttpBean.okHttpClient = new OkHttpClient.Builder()
                .connectTimeout(6, TimeUnit.MINUTES)
                .readTimeout(6, TimeUnit.MINUTES)
                .writeTimeout(6, TimeUnit.MINUTES)
                .build();
        return okHttpClient;
    }
}
